import axios from "axios";
// 添加请求拦截器，在请求头中加token
axios.interceptors.request.use(config => {
    //配置token
    if (sessionStorage.getItem('token')) {
      config.headers['token'] = sessionStorage.getItem('token');
    }
    return config;
  }, error => {
    return Promise.reject(error);
  })
  //配置响应的参数
  axios.interceptors.response.use(response => {
  //当token过期或者不存在时，后台返回状态码401，此时页面跳转到登录页面
     if (response.status === 401) {
      router.push({ path: "/" });
      Notification({
        message: "登录信息已过期,请重新登录",
        type: "error",
      });
      return ;
    }
    return response
  
  }, error => {
    return Promise.reject(error);
  });